import service from '/@/utils/request';

/**
 * （不建议写成 request.post(xxx)，因为这样 post 时，无法 params 与 data 同时传参）
 *
 * 登录api接口集合
 * @method signIn 用户登录
 * @method signOut 用户退出登录
 */
export const authLoginApi = (data: object) => {

    return service({
        url: 'v0/system/auth/login',
        method: 'post',
        data,
    });
}

export const authGetCapcha = () => {
    return service({
        url: 'v0/system/auth/getCaptcha',
        method: 'get',
    });
}
export const authUserinfo = () => {
    return service({
        url: 'v0/system/auth/userinfo',
        method: 'get',
    });
}
export const authMenuTree = () => {
    return service({
        url: 'v0/system/auth/menuTree',
        method: 'get',
    });
}
export const useSystemAdminQueryApi = (code: string,) => {
    return service({
        url: `v0/system/admin/query`,
        method: 'GET',
        params: { code: code },
    });
}
export const useSystemAdminPageApi = (formData?: object) => {
    return service({
        url: `v0/system/admin/page`,
        method: 'POST',
        data: formData
    });
}

export const useSystemAdminCreateApi = (formData: object) => {
    return service({
        url: `v0/system/admin/create`,
        method: 'POST',
        data: formData
    });
}
export const useSystemAdminUpdateApi = (formData: object) => {
    return service({
        url: `v0/system/admin/update`,
        method: 'PUT',
        data: formData
    });
}

export const useSystemAdminDeleteApi = (param: string | string[]) => {
    let arrList: string[] = []

    if (param instanceof Array) {
        arrList = param
    } else {
        arrList.push(param)
    }

    return service({
        url: `v0/system/admin/delete`,
        method: 'DELETE',
        data: { codeList: arrList }
    });
}

export const useSystemAdminListApi = () => {
    return service({
        url: `v0/system/admin/list`,
        method: 'GET'
    });
}

